import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import { sync } from 'vuex-router-sync';
import store from 'store';
import app from './app.vue';
import App from 'app';
import Layout from 'component/layout/app';
import Cookies from 'js-cookie';
import { isWx } from '../../utils/ua';

App.use(ElementUI);

App.component(Layout.name, Layout);

import router from 'component/app/router';
sync(store, router);

if (typeof window === 'object' && isWx()) {
	const openid = Cookies.get('openid') || '';
	if (!openid) {
		const { origin, href } = window.location;
		const path = encodeURIComponent(href.replace(origin, ''));
		const lnk = `${origin}/wechat/redirect?path=${path}`;
		window.location.replace(lnk);
	}
}

export default App.init({
	base: '/app',
	...app,
	router,
	store,
});
